﻿using System.Configuration;
using ChannelVN.CMS.Common;
using System.Web;

namespace ChannelVN.CMS.DynamicLayout.FrontEnd.Common
{
    public class ConfigValues
    {
        public static string HostUrl
        {
            get
            {
                var url = AppSettings.GetString("HOST_URL");
                if (!url.EndsWith("/")) url += "/";
                return url;
            }
        }
        public static string DynamicLayoutUrl
        {
            get
            {
                var url = AppSettings.GetString("DYNAMIC_LAYOUT_URL");
                if (!url.EndsWith("/")) url += "/";
                return url;
            }
        }
        public static string DynamicLayoutSecretKey
        {
            get
            {
                var key = AppSettings.GetString("SECRET_KEY_FOR_FRONT_END");
                if (!string.IsNullOrEmpty(key)) key = Utility.CreateMD5Checksum(key);

                return key;
            }
        }
        public static string PageConfigCachingFolder
        {
            get
            {
                var path = AppSettings.GetString("PAGE_CONFIG_CACHING_FOLDER");
                if (!string.IsNullOrEmpty(path))
                {
                    path = HttpContext.Current.Server.MapPath(path);
                    if (!path.EndsWith(@"\")) path += @"\";
                }
                return path;
            }
        }
        public static string FrontEndConnectionString
        {
            get
            {
                var connectionStringName = AppSettings.GetString("FRONT_END_CONNECTION_STRING");
                if (string.IsNullOrEmpty(connectionStringName))
                {
                    connectionStringName = "FRONT_END";
                }
                return AppSettings.GetConnection(connectionStringName);
            }
        }
        public static string NewsConfigNameForDynamicLayout
        {
            get { return "DynamicLayoutConfig"; }
        }
        public static bool IsGetDefaultPageConfig
        {
            get { return AppSettings.GetString("GET_DEFAULT_PAGE_CONFIG") == "1"; }
        }
    }
}
